{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b4694c85",
   "metadata": {},
   "source": [
    "* 2022/09/13\n",
    "* Python 课堂笔记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "20fce330",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## 上周回顾(range())\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0913e0b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# for + range 决定循环的次数\n",
    "\n",
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3065429b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "037cc62e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "565feafa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a2052bdb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# start? stop? step?"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f63cc14e",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type():检查类型\n",
    "    \n",
    "> 1. 数值   \n",
    ">> 1.int   \n",
    ">> 2.float   \n",
    ">> 3.complex\n",
    "\n",
    "> 2.字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "37343816",
   "metadata": {},
   "source": [
    "# 1. 数值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e87bef00",
   "metadata": {},
   "source": [
    "# 2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "35c32f21",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "618d55b5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = ''''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81e6a157",
   "metadata": {},
   "outputs": [],
   "source": [
    "nfu_news_pages_html = \n",
    "\"\"\"\n",
    "\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b1dfa5a",
   "metadata": {},
   "source": [
    "# 2.2关于字符串的方法及函数(https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)\n",
    "\n",
    "* Single quotes: 'allows embedded \"double\" quotes'\n",
    "\n",
    "* Double quotes: \"allows embedded 'single' quotes\"\n",
    "\n",
    "* Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3087b9f1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "659d570d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0] # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "706024be",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'州'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "84283483",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "2b9770e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "1e724d5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6] # 取一定范围的值，这种方法我们称为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7c5c7864",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到内容itme,又可以获取索引值的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "6bf29afe",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 广\n",
      "7 州\n",
      "8 市\n",
      "9 从\n",
      "10 化\n",
      "11 温\n",
      "12 泉\n",
      "13 镇\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "a577f4e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州这个词在这段文本中\n",
      "广州这个词在这段文本中\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本 title 中的内容\n",
    "for i,j in enumerate (title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1]== \"州\":\n",
    "            print(\"广州这个词在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "177c5938",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59 in 检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc84ccfc",
   "metadata": {},
   "source": [
    "* 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "27ea27d3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "# 字符串不可以和数字进行连接\n",
    "print(\"你好\"+ \",\" + \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ace58b32",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d1e674e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串不可以用来运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "f590af11",
   "metadata": {},
   "outputs": [],
   "source": [
    "width = 16\n",
    "heigt = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "cc638ef8",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "14d08ee7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "144"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "205589d3",
   "metadata": {},
   "source": [
    "* 字符串的方法\n",
    "\n",
    "> 1. str.capitalize():可以将首字母转成大写\n",
    "> 2. str.count():数量？\n",
    "> 3. str.split() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "17f8f810",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "b77c8845",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "96709e94",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "5e05b841",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "f19e521e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院广州', '从化温泉镇']"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"市\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "aea1932f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
